package com.ruoyi.memo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.memo.domain.MemoNote;
import com.ruoyi.memo.service.IMemoNoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 便签Controller
 * 
 * @author ruoyi
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/memo/note")
@Api(tags = "便签管理")
public class MemoNoteController extends BaseController
{
    @Autowired
    private IMemoNoteService memoNoteService;

    @ApiOperation("132")
    @GetMapping("/userlist")
    public TableDataInfo userlist(MemoNote memoNote)
    {
        memoNote.setUserId(SecurityUtils.getUserId());
        startPage();
        List<MemoNote> list = memoNoteService.selectMemoNoteList(memoNote);
        return getDataTable(list);
    }
    /**
     * 查询便签列表
     */
//    @PreAuthorize("@ss.hasPermi('memo:note:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemoNote memoNote)
    {
        startPage();
        List<MemoNote> list = memoNoteService.selectMemoNoteList(memoNote);
        return getDataTable(list);
    }

    /**
     * 导出便签列表
     */
//    @PreAuthorize("@ss.hasPermi('memo:note:export')")
    @Log(title = "便签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemoNote memoNote)
    {
        List<MemoNote> list = memoNoteService.selectMemoNoteList(memoNote);
        ExcelUtil<MemoNote> util = new ExcelUtil<MemoNote>(MemoNote.class);
        util.exportExcel(response, list, "便签数据");
    }

    /**
     * 获取便签详细信息
     */
//    @PreAuthorize("@ss.hasPermi('memo:note:query')")
    @GetMapping(value = "/{noteId}")
    public AjaxResult getInfo(@PathVariable("noteId") Long noteId)
    {
        return success(memoNoteService.selectMemoNoteByNoteId(noteId));
    }

    /**
     * 新增便签
     */
//    @PreAuthorize("@ss.hasPermi('memo:note:add')")
    @Log(title = "便签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemoNote memoNote)
    {

        memoNote.setUserId(SecurityUtils.getUserId());
        return toAjax(memoNoteService.insertMemoNote(memoNote));
    }

    /**
     * 修改便签
     */
//    @PreAuthorize("@ss.hasPermi('memo:note:edit')")
    @Log(title = "便签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemoNote memoNote)
    {
        return toAjax(memoNoteService.updateMemoNote(memoNote));
    }

    /**
     * 删除便签
     */
//    @PreAuthorize("@ss.hasPermi('memo:note:remove')")
    @Log(title = "便签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noteIds}")
    public AjaxResult remove(@PathVariable Long[] noteIds)
    {
        return toAjax(memoNoteService.deleteMemoNoteByNoteIds(noteIds));
    }
}
